﻿using System;
using System.Data;
using System.Web.UI;
using DevExpress.Web;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class MyOrders : MemberPage
{
     

    protected void Page_Init(object sender, EventArgs e)
    {
        Bind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        GridViewDataColumn gcImg = (GridViewDataColumn)gvRezerve.Columns["Scan"];
        if (gcImg != null)
            gcImg.DataItemTemplate = new Utils.PhotoColumnTemplate();
    }

    protected void gvRezerve_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType != DevExpress.Web.GridViewRowType.Data) return;

        object val = e.GetValue("Status").ToString();
            switch (val.ToString())
            {
                case "SENT":
                    //e.Row.BackColor = Color.Moccasin;
                    e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#99CCFF");
                    break;
                case "IN PRODUCTION":
                    e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#99CC33");
                    break;
                case "CANCELLED":
                    e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#FF3300");
                    break;
                case "PROCESSING":
                    e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFCC33");
                    break;
            }
        

    }

    private void Bind()
    {
        DataSet ds = DataAccess.web2GetDU4Orders();
        DataTable dt = ds.Tables[0];

        ConfExpertMaster m = (ConfExpertMaster)Master;
        m.TableToExport = dt;

        gvOzet.DataSource = ds.Tables[1];
        chart.DataSourceID = "";
        chart.DataSource = ds.Tables[1];

        ASPxSummaryItem s = new ASPxSummaryItem("Total", DevExpress.Data.SummaryItemType.Sum);
        s.DisplayFormat = "∑ {0:n0}";
        s.ShowInColumn = "Total";
        gvOzet.TotalSummary.Add(s);

        ((GridViewDataTextColumn)gvOzet.Columns["Total"]).PropertiesTextEdit.DisplayFormatString = "#,#.0;#,#.0; ;";

        gvOzet.DataBind();
        chart.DataBind();

        gvRezerve.DataSource = dt;

        gvRezerve.Columns.Clear();
        gvRezerve.TotalSummary.Clear(); 

        foreach (DataColumn col in dt.Columns)
        {
            string colName = col.ColumnName.ToLower();
            if (colName == "productıd")
            {
                GridViewDataColumn gcImg = new GridViewDataColumn();
                gcImg.DataItemTemplate = new Utils.PhotoColumnTemplate();
                gcImg.Caption = "Scan";
                gcImg.CellStyle.Paddings.Padding = 1;
                gcImg.Width = 33;
                gcImg.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                gvRezerve.Columns.Add(gcImg);
            }
            else
            {
                GridViewDataTextColumn gc = new GridViewDataTextColumn();
                gc.FieldName = col.ColumnName;
                gc.Settings.AutoFilterCondition = AutoFilterCondition.Contains;

                if (colName != "description")
                    gc.CellStyle.Wrap = DevExpress.Utils.DefaultBoolean.False;

                ASPxSummaryItem summary;
               

                if (colName.Contains("price"))
                {
                    gc.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                    gc.PropertiesTextEdit.DisplayFormatString = "#,#.0;#,#.0; ;";
                }

                else if (colName.Contains("qty"))
                {
                    gc.PropertiesTextEdit.DisplayFormatString = "#,#.0;#,#.0; ;";
                    gc.Settings.AutoFilterCondition = AutoFilterCondition.GreaterOrEqual;
                    summary = new ASPxSummaryItem(gc.FieldName, DevExpress.Data.SummaryItemType.Sum);
                    summary.DisplayFormat = "∑ {0:n0}";
                    summary.ShowInColumn = col.ColumnName;
                    gvRezerve.TotalSummary.Add(summary);
                }

                else if (colName.Contains("total"))
                {
                    gc.PropertiesTextEdit.DisplayFormatString = "#,#;#,#; ;";
                    gc.Settings.AutoFilterCondition = AutoFilterCondition.GreaterOrEqual;
                    summary = new ASPxSummaryItem(gc.FieldName, DevExpress.Data.SummaryItemType.Sum);
                    summary.DisplayFormat = "∑ {0:n0}";
                    summary.ShowInColumn = col.ColumnName;
                    gvRezerve.TotalSummary.Add(summary);
                }

                gvRezerve.Columns.Add(gc);
            }
        }
        gvRezerve.DataBind();
    }


     
    
}